/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.server.db.tasks;

import pl.cezary.butler.walili.common.User;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.jdbc.core.SingleColumnRowMapper;

/**
 * HSQL DB COMPAT
 *
 * @author Przemysław Bałdyga
 */
public class DoesUserExistsTask extends FetchingTask<Boolean> {

    private final String LOGIN;
    private final String HASLO;
    private transient boolean isUser;
    private static final Logger log = Logger.getLogger("ZadanieIsUser");

    public DoesUserExistsTask(User user) {
        LOGIN = user.getLogin();
        HASLO = user.getHaslo();
    }

    @Override
    public void executeInternal() {
        isUser = getJdbcTemplate().queryForObject("SELECT EXISTS(SELECT * FROM users WHERE login LIKE ? AND haslo LIKE ?)", new SingleColumnRowMapper<Boolean>(Boolean.class), LOGIN, HASLO);        
    }

    @Override
    protected Boolean $getResultsNonLocking() {
        return isUser;
    }
    
}
